<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="./common/header.jsp"%>
<body>

<%@ include file="./common/top.jsp"%>
		
		<div class="container" id="mainContainer">
			<form class="form-inline" style="margin-top: 15px;text-align: left;display: none;" id="">
			 
		  		 <div class="form-group">
		    		<label class="sr-only" for=""></label>  
					<input class="form-control" type="text"   name="title" id="title_search_id" style="width:520px;" placeholder="商品标题"/>
		  		 </div> 
				<a href="#" id="search_id" class="btn btn-primary"><i class="icon-search icon-white"></i>搜索</a>
				 
			</form>
			
			<div align="right"  style="position: relative;">
				<a type="button"  id="batch_send"   style="position: fixed;right:300px;top:10px;z-index:999999;"  class="btn btn-primary" >批量发货</a>
			</div>
			
			
			<div>
				<h3> 已处理一订单列表</h3>
			</div>
			<table style="margin-top:20px;margin-bottom:100px;" class="table table-striped table-hover">
					<thead>
						<tr>
							<th width="undefined" data-col="updateDate">下单时间</th>
							<th width="undefined" data-col="order_outerid">订单号</th>
							<th width="undefined" data-col="order_remark">商品图片</th>
							<th width="undefined" data-col="order_host">来源</th>
							<th width="undefined" data-col="">商品信息</th>
							<th width="undefined" data-col="order_mobile">手机</th>
							<th width="undefined" data-col="order_name">收货人</th>
							<th width="100px" data-col="order_addr">地址</th>
							<th width="undefined" data-col="order_totalPrice">总价格</th>
							<th width="200px" data-col="order_tradeStatus">操作</th>
						</tr>
					</thead>		
					<tbody>
						<tr>
							<td colspan="100">暂无数据！</td>
						</tr>
					</tbody>
			</table>
     </div>
     
     <script type="text/tmpl" id="tr_model_id">
     	<tr>
					<td data-col="updateDate" class="updateDate"></td>
					<td data-col="order_outerid" class="outerid"></td>
					<td data-col="order_remark"  class="remark"></td>
					<td data-col="order_host" class="host"></td>
					<td data-col="">
						<div style="font-size:11px;width:100px;" class="goods-info"></div>
					</td>
					<td data-col="order_mobile" class="mobile"></td>
					<td data-col="order_name" class="name"></td>
					<td data-col="order_addr" class="addr"></td>
					<td data-col="order_totalPrice" class="totalPrice"></td>
					<td><input class="wuliu-id" data-id="" type="text" style="width:200px;background:#ECFFFF;padding-left:5px;" placeholder="批量发货物流发货单号"/></td>
		 </tr>
     </script>
     
	<script>
		$(function() {
			
			$("#search_id").click(function(){
				search();
				return false;
			});
			
			 $("#title_search_id").bind('keypress',function(event){
		            if(event.keyCode == "13")    
		            { 
		            	search();
		            	return false;
		            }
			 });
			 
			 search();
			function search(){
				
				jQuery.ajax({
					type : 'Get',
					contentType : 'application/json',
					url : '../admin/order/readySendList.do',
					dataType : 'json',
					success : function(obj) {
						if(obj.result){
							var list =obj.obj;
							if(list.length >0){
								$("tbody").html("");
							}else{
								$("tbody").html('<tr><td colspan="100">暂无数据！</td></tr>');
							}
							for(var i = 0 ;i<list.length;i++){
								var orderObj = list[i];
								var goodsList = orderObj.goodsList;
								var html = $("#tr_model_id").html();
								$("tbody").append(html);
								var newTr = $("tbody tr").last();
								newTr.find(".updateDate").html(orderObj.updateDate);
								newTr.find(".outerid").html(orderObj.order.outerid);
								newTr.find(".host").html(orderObj.order.host);
								var html = "";
								var imgHtml = "";
								for(var j = 0 ;j<goodsList.length;j++){
									var goodsObj = goodsList[j];
									var goods = goodsObj.goods;
									html = html +'<a target="_blank" href="${ctx}/detailGoods/'+goods.id+'"  class="goods-title">'+goods.title+'</a>&nbsp;×'+goodsObj.num+'，颜色：'+goodsObj.color+'，尺码：'+goodsObj.size+'<br>';
									if(goodsObj.pic){
										imgHtml = imgHtml + '<img style="width:60px;height:60px;" src="${ctx}/upload/download.do?fileName='+goodsObj.pic+'"/>';
									}else{
										imgHtml = imgHtml + '<img style="width:60px;height:60px;" src="${ctx}/upload/download.do?fileName='+goods.picName+'"/>';
									}
								}
								newTr.find(".goods-info").html(html);
								newTr.find(".mobile").html(orderObj.order.mobile);
								newTr.find(".name").html(orderObj.order.name);
								newTr.find(".addr").html(orderObj.order.addr);
								newTr.find(".totalPrice").html("￥"+orderObj.order.totalPrice);
								newTr.find(".addr").html(orderObj.order.addr);
								newTr.find(".remark").html(imgHtml);
								newTr.find(".wuliu-id").attr("data-id",orderObj.order.id);
							}
						}
					},
					error : function(data) {
						
					}
				});
				
			}
			
			//绑定批量发货
			$("#batch_send").click(function(){
				var wuLiuIds = "";
				$("tbody").find(".wuliu-id").each(function(){
					if($(this).val()){
						var id = $(this).data("id");
						var val = $(this).val();
						var pingjie = id+"-"+val;
						wuLiuIds = wuLiuIds+pingjie+",";
					}
				});
				
				if(!wuLiuIds){
					alert("没有填写任何运单号！");
					return false;
				}else{
					wuLiuIds = wuLiuIds.substring(0,wuLiuIds.length-1);
				}
				jQuery.ajax( {
					type : 'POST',
					url : '${ctx}/admin/order/batchShip.do',
					dataType : 'json',
					data : {
						wuLiuIds:wuLiuIds
					},
					success : function(obj) {
						if(obj.result){
							window.top.jWei.Tips.success("操作成功！");
							search();
							 
						}else{
							jWei.Tips.error(obj.errorMsg);
						}
						$("#mainContainer").hideLoading();
					},
					error : function() {
						window.top.jWei.Tips.error("数据库异常！");
					}
				});
				return false;
			});
			
		});
	</script>

</body>
</html>